home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Forms Misc / currency-format.izs < prev    next >
Text File  |  2005-09-28  |  3KB  |  122 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Currency Format 
  4. <!/TITLE>
  5.  
  6. <!DESCRIPTION>This script accepts a number or string and formats it like U.S. currency. Adds the dollar sign, rounds to two places past the decimal, adds place holding zeros, and commas where appropriate.<!/DESCRIPTION> 
  7.  
  8. <!CATEGORY>Forms<!/CATEGORY>
  9.  
  10. <!SCRIPT>
  11. <!-- START OF SCRIPT -->
  12.  
  13.  
  14. <!-- HOW TO INSTALL CURRENCY FORMAT:
  15.  
  16.   1.  Copy code into the HEAD section of document
  17.   2.  Put last coding into the BODY section of document  -->
  18.  
  19. <!-- STEP ONE: Add code into HEAD section of document  -->
  20.  
  21. <HEAD>
  22.  
  23. <SCRIPT LANGUAGE="JavaScript">
  24. <!-- Original:  Cyanide_7 (leo7278@hotmail.com) -->
  25. <!-- Web Site:  http://www7.ewebcity.com/cyanide7 -->
  26.  
  27.  
  28.  
  29. <!-- Begin
  30. function formatCurrency(num) {
  31. num = num.toString().replace(/\$|\,/g,'');
  32. if(isNaN(num))
  33. num = "0";
  34. sign = (num == (num = Math.abs(num)));
  35. num = Math.floor(num*100+0.50000000001);
  36. cents = num%100;
  37. num = Math.floor(num/100).toString();
  38. if(cents<10)
  39. cents = "0" + cents;
  40. for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  41. num = num.substring(0,num.length-(4*i+3))+','+
  42. num.substring(num.length-(4*i+3));
  43. return (((sign)?'':'-') + '$' + num + '.' + cents);
  44. }
  45. //  End -->
  46. </script>
  47. </HEAD>
  48.  
  49. <!-- STEP TWO: Add code into BODY section of document  -->
  50.  
  51. <BODY>
  52.  
  53. <center>
  54. <form name=currencyform>
  55. Enter a number then click the button: <input type=text name=input size=10 value="1000434.23">
  56. <input type=button value="Convert" onclick="this.form.input.value=formatCurrency(this.form.input.value);">
  57. <br><br>
  58. or enter a number and click another field: <input type=text name=input2 size=10 value="1000434.23" onBlur="this.value=formatCurrency(this.value);">
  59. </form>
  60. </center>
  61.  
  62.  
  63. <!-- END OF SCRIPT -->
  64. <!/SCRIPT>
  65.  
  66. <!PREVIEW>
  67. <!-- START OF SCRIPT -->
  68.  
  69.  
  70. <!-- HOW TO INSTALL CURRENCY FORMAT:
  71.  
  72.   1.  Copy code into the HEAD section of document
  73.   2.  Put last coding into the BODY section of document  -->
  74.  
  75. <!-- STEP ONE: Add code into HEAD section of document  -->
  76.  
  77. <HEAD>
  78.  
  79. <SCRIPT LANGUAGE="JavaScript">
  80. <!-- Original:  Cyanide_7 (leo7278@hotmail.com) -->
  81. <!-- Web Site:  http://www7.ewebcity.com/cyanide7 -->
  82.  
  83.  
  84.  
  85. <!-- Begin
  86. function formatCurrency(num) {
  87. num = num.toString().replace(/\$|\,/g,'');
  88. if(isNaN(num))
  89. num = "0";
  90. sign = (num == (num = Math.abs(num)));
  91. num = Math.floor(num*100+0.50000000001);
  92. cents = num%100;
  93. num = Math.floor(num/100).toString();
  94. if(cents<10)
  95. cents = "0" + cents;
  96. for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  97. num = num.substring(0,num.length-(4*i+3))+','+
  98. num.substring(num.length-(4*i+3));
  99. return (((sign)?'':'-') + '$' + num + '.' + cents);
  100. }
  101. //  End -->
  102. </script>
  103. </HEAD>
  104.  
  105. <!-- STEP TWO: Add code into BODY section of document  -->
  106.  
  107. <BODY>
  108.  
  109. <center>
  110. <form name=currencyform>
  111. Enter a number then click the button: <input type=text name=input size=10 value="1000434.23">
  112. <input type=button value="Convert" onclick="this.form.input.value=formatCurrency(this.form.input.value);">
  113. <br><br>
  114. or enter a number and click another field: <input type=text name=input2 size=10 value="1000434.23" onBlur="this.value=formatCurrency(this.value);">
  115. </form>
  116. </center>
  117.  
  118. <!-- END OF SCRIPT -->
  119. <!/PREVIEW>
  120.  
  121. <!RELATED>NONE<!/RELATED>
  122.